package com.mlk.core.util;

import com.fasterxml.jackson.core.type.TypeReference;
import com.mlk.core.config.DeptConfig;
import com.mlk.rbac.po.SysDept;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

/**
 * 部门的工具类
 * @author xulu
 */
@Component
public class DeptUtils {

    private DeptUtils(){}

    private static RedisTemplate<String,String> redisTemplate;

    @Autowired
    public  void setRedisTemplate(RedisTemplate<String, String> redisTemplate) {
        DeptUtils.redisTemplate = redisTemplate;
    }

    /**
     * 通过部门的id查询部门的信息
     * @param id
     * @return
     */
    public static final SysDept findDeptById(Integer id){
        String str = redisTemplate.opsForValue().get(DeptConfig.CACHE_PREFIX + id);
        if(StringUtils.isEmpty(str)){
            return null;
        }
        return JSONUtils.jSONstringToObj(str, new TypeReference<SysDept>() {
        });
    }

}
